Add configure option to reduce visual clutter at boot time
authorJulian Andres Klode <julian.klode@canonical.com>
Tue, 25 Jul 2023 13:35:52 +0000 (15:35 +0200)
committerJulian Andres Klode <jak@debian.org>
Sun, 2 Nov 2025 11:08:11 +0000 (12:08 +0100)
If this option is enabled, then do all of the following:

Don't display introductory message about line editing unless we're
actually offering a shell prompt.  (This is believed to be a workaround
for a different bug.  We'll go with this for now, but will drop this in
favour of a better fix upstream if somebody figures out what that is.)

Don't clear the screen just before booting if we never drew the menu in
the first place.

Remove verbose messages printed before reading configuration.  In some
ways this is awkward because it makes debugging harder, but it's a
requirement for a smooth-looking boot process; we may be able to do
better in future.  Upstream doesn't want this, though.

Disable the cursor as well, for similar reasons of tidiness.

Suppress kernel/initrd progress messages, except in recovery mode.

Suppress "GRUB loading" message unless Shift is held down.  Upstream
doesn't want this, as it makes debugging harder.  Ubuntu wants it to
provide a cleaner boot experience.

Author: Will Thompson <will@willthompson.co.uk>
Bug-Ubuntu: https://bugs.launchpad.net/bugs/386922
Bug-Ubuntu: https://bugs.launchpad.net/bugs/861048
Forwarded: (partial) http://lists.gnu.org/archive/html/grub-devel/2009-09/msg00056.html
Last-Update: 2021-09-24

Patch-Name: maybe-quiet.patch

Gbp-Pq: Name maybe-quiet.patch

config.h.in
configure.ac
grub-core/boot/i386/pc/boot.S
grub-core/boot/i386/pc/diskboot.S
grub-core/kern/main.c
grub-core/kern/rescue_reader.c
grub-core/normal/main.c
grub-core/normal/menu.c
util/grub.d/10_linux.in

index 9b1d39971858778c8fb499675c3e5b287f8a0315..9d6f3694e574e08f724d1e3806483b61a1829ae2 100644 (file)
@@ -16,6 +16,8 @@
 /* Define to 1 to enable disk cache statistics.  */
 #define DISK_CACHE_STATS @DISK_CACHE_STATS@
 #define BOOT_TIME_STATS @BOOT_TIME_STATS@
+/* Define to 1 to make GRUB quieter at boot time.  */
+#define QUIET_BOOT @QUIET_BOOT@
 
 /* We don't need those.  */
 #define MINILZO_CFG_SKIP_LZO_PTR 1
index b88067703e8cf089c98aafa2e7ab273c34cf6678..b34cbde09547b2f85c29e5a81e4a6a6636bf5762 100644 (file)
@@ -2128,6 +2128,17 @@ else
 fi
 AC_SUBST([UBUNTU_RECOVERY])
 
+AC_ARG_ENABLE([quiet-boot],
+              [AS_HELP_STRING([--enable-quiet-boot],
+                              [emit fewer messages at boot time (default=no)])],
+              [], [enable_quiet_boot=no])
+if test x"$enable_quiet_boot" = xyes ; then
+  QUIET_BOOT=1
+else
+  QUIET_BOOT=0
+fi
+AC_SUBST([QUIET_BOOT])
+
 LIBS=""
 
 AC_SUBST([FONT_SOURCE])
@@ -2409,5 +2420,10 @@ echo "With stack smashing protector: Yes"
 else
 echo "With stack smashing protector: No"
 fi
+if [ x"$enable_quiet_boot" = xyes ]; then
+echo With quiet boot: Yes
+else
+echo With quiet boot: No
+fi
 echo "*******************************************************"
 ]
index 2bd0b2d2866b4d79a37d23b93842fef44771eb46..b0c0f2225e73ecc033d8a7bc3c989af26b44f6cd 100644 (file)
@@ -19,6 +19,9 @@
 
 #include <grub/symbol.h>
 #include <grub/machine/boot.h>
+#if QUIET_BOOT && !defined(HYBRID_BOOT)
+#include <grub/machine/memory.h>
+#endif
 
 /*
  *  defines for the code go here
@@ -249,9 +252,17 @@ real_start:
        /* save drive reference first thing! */
        pushw   %dx
 
+#if QUIET_BOOT && !defined(HYBRID_BOOT)
+       /* is either shift key held down? */
+       movw    $(GRUB_MEMORY_MACHINE_BIOS_DATA_AREA_ADDR + 0x17), %bx
+       testb   $3, (%bx)
+       jz      2f
+#endif
+
        /* print a notification message on the screen */
        MSG(notification_string)
 
+2:
        /* set %si to the disk address packet */
        movw    $disk_address_packet, %si
 
index c1addc0df29bc78009238690a9514ea301bf3a29..9b6d7a7edc36c9e5778ff42f5d8b3d0ea5bffa52 100644 (file)
@@ -18,6 +18,9 @@
 
 #include <grub/symbol.h>
 #include <grub/machine/boot.h>
+#if QUIET_BOOT
+#include <grub/machine/memory.h>
+#endif
 
 /*
  *  defines for the code go here
 
 #define MSG(x) movw $x, %si; call LOCAL(message)
 
+#if QUIET_BOOT
+#define SILENT(x)      call LOCAL(check_silent); jz LOCAL(x)
+#else
+#define SILENT(x)
+#endif
+
        .file   "diskboot.S"
 
        .text
@@ -50,11 +59,14 @@ _start:
        /* save drive reference first thing! */
        pushw   %dx
 
+       SILENT(after_notification_string)
+
        /* print a notification message on the screen */
        pushw   %si
        MSG(notification_string)
        popw    %si
 
+LOCAL(after_notification_string):
        /* this sets up for the first run through "bootloop" */
        movw    $LOCAL(firstlist), %di
 
@@ -279,7 +291,10 @@ LOCAL(copy_buffer):
        /* restore addressing regs and print a dot with correct DS
           (MSG modifies SI, which is saved, and unused AX and BX) */
        popw    %ds
+       SILENT(after_notification_step)
        MSG(notification_step)
+
+LOCAL(after_notification_step):
        popa
 
        /* check if finished with this dataset */
@@ -295,8 +310,11 @@ LOCAL(copy_buffer):
 /* END OF MAIN LOOP */
 
 LOCAL(bootit):
+       SILENT(after_notification_done)
        /* print a newline */
        MSG(notification_done)
+
+LOCAL(after_notification_done):
        popw    %dx     /* this makes sure %dl is our "boot" drive */
        ljmp    $0, $(GRUB_BOOT_MACHINE_KERNEL_ADDR + 0x200)
 
@@ -320,6 +338,14 @@ LOCAL(general_error):
 /* go here when you need to stop the machine hard after an error condition */
 LOCAL(stop):   jmp     LOCAL(stop)
 
+#if QUIET_BOOT
+LOCAL(check_silent):
+       /* is either shift key held down? */
+       movw    $(GRUB_MEMORY_MACHINE_BIOS_DATA_AREA_ADDR + 0x17), %bx
+       testb   $3, (%bx)
+       ret
+#endif
+
 notification_string:   .asciz "loading"
 
 notification_step:     .asciz "."
index 143a232b8d3e0b5f9828511b8811a0099dd35524..60eed47a5f209639eedfddb9a4a0f6ee6f21f082 100644 (file)
@@ -303,6 +303,10 @@ reclaim_module_space (void)
 void __attribute__ ((noreturn))
 grub_main (void)
 {
+#if QUIET_BOOT
+  struct grub_term_output *term;
+#endif
+
 #ifdef GRUB_STACK_PROTECTOR
   /*
    * This call should only be made from a function that does not return because
@@ -318,12 +322,18 @@ grub_main (void)
 
   grub_boot_time ("After machine init.");
 
+#if QUIET_BOOT
+  /* Disable the cursor until we need it.  */
+  FOR_ACTIVE_TERM_OUTPUTS(term)
+    grub_term_setcursor (term, 0);
+#else
   /* This breaks flicker-free boot on EFI systems, so disable it there. */
 #ifndef GRUB_MACHINE_EFI
   /* Hello.  */
   grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT);
   grub_printf ("Welcome to GRUB!\n\n");
   grub_setcolorstate (GRUB_TERM_COLOR_STANDARD);
+#endif
 #endif
 
   /* Init verifiers API. */
@@ -366,5 +376,12 @@ grub_main (void)
   grub_boot_time ("After execution of embedded config. Attempt to go to normal mode");
 
   grub_load_normal_mode ();
+
+#if QUIET_BOOT
+  /* If we have to enter rescue mode, enable the cursor again.  */
+  FOR_ACTIVE_TERM_OUTPUTS(term)
+    grub_term_setcursor (term, 1);
+#endif
+
   grub_rescue_run ();
 }
index a71ada8fb7da2eae6ee7135fe234fb1755ca78b0..932254a94130d8ca65f6800686d74b50fe79b074 100644 (file)
@@ -78,6 +78,10 @@ grub_rescue_read_line (char **line, int cont,
 void __attribute__ ((noreturn))
 grub_rescue_run (void)
 {
+#if QUIET_BOOT
+  grub_printf ("Entering rescue mode...\n");
+#endif
+
   /* Stall if the CLI has been disabled */
   if (grub_is_cli_disabled () || grub_is_cli_need_auth ())
     {
@@ -91,8 +95,6 @@ grub_rescue_run (void)
       while (1);
     }
 
-  grub_printf ("Entering rescue mode...\n");
-
   while (1)
     {
       char *line;
index 96abfda2f7e73674d5d7c3e36f8b241eb2afcbd8..c363874e2daa6acff78e73c2deaa0bb5bf688da9 100644 (file)
@@ -408,6 +408,15 @@ static grub_err_t
 grub_normal_read_line_real (char **line, int cont, int nested)
 {
   const char *prompt;
+#if QUIET_BOOT
+  static int displayed_intro;
+
+  if (! displayed_intro)
+    {
+      grub_normal_reader_init (nested);
+      displayed_intro = 1;
+    }
+#endif
 
   if (cont)
     /* TRANSLATORS: it's command line prompt.  */
@@ -464,7 +473,9 @@ grub_cmdline_run (int nested, int force_auth)
       return;
     }
 
+#if !QUIET_BOOT
   grub_normal_reader_init (nested);
+#endif
 
   while (1)
     {
index b946c834d899324a777fff29a2fc5fe3b1ab940d..1b8b91bb93f3efcf22224e7e57ea8b0631c64841 100644 (file)
@@ -815,14 +815,18 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot, int *notify_boot)
 static void
 notify_booting (grub_menu_entry_t entry, void *userdata)
 {
+#if !QUIET_BOOT
   int *notify_boot = userdata;
-
   if (*notify_boot)
     {
       grub_printf ("  ");
       grub_printf_ (N_("Booting `%s'"), entry->title);
       grub_printf ("\n\n");
     }
+#else
+  (void) userdata;
+  (void) entry;
+#endif
 }
 
 /* Callback invoked when a default menu entry executed because of a timeout
@@ -871,6 +875,9 @@ show_menu (grub_menu_t menu, int nested, int autobooted)
       grub_menu_entry_t e;
       int auto_boot;
       int notify_boot;
+#if QUIET_BOOT
+      int initial_timeout = grub_menu_get_timeout ();
+#endif
 
       boot_entry = run_menu (menu, nested, &auto_boot, &notify_boot);
       if (boot_entry < 0)
@@ -885,7 +892,11 @@ show_menu (grub_menu_t menu, int nested, int autobooted)
                                         &execution_callback, &notify_boot);
       else
        {
-         grub_cls ();
+#if QUIET_BOOT
+          /* Only clear the screen if we drew the menu in the first place.  */
+          if (initial_timeout != 0)
+#endif
+           grub_cls ();
          grub_menu_execute_entry (e, 0);
        }
       if (autobooted)
index 19a225160356bf349df4c607e19e254b17f3b982..7ef86724c1a42aca314e5e3478cb7327f9af9af1 100644 (file)
@@ -21,6 +21,7 @@ prefix="@prefix@"
 exec_prefix="@exec_prefix@"
 datarootdir="@datarootdir@"
 ubuntu_recovery="@UBUNTU_RECOVERY@"
+quiet_boot="@QUIET_BOOT@"
 
 . "$pkgdatadir/grub-mkconfig_lib"
 
@@ -154,20 +155,28 @@ linux_entry ()
     fi
     printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/"
   fi
-  message="$(gettext_printf "Loading Linux %s ..." ${version})"
-  sed "s/^/$submenu_indentation/" << EOF
+  if [ x"$quiet_boot" = x0 ] || [ x"$type" != xsimple ]; then
+    message="$(gettext_printf "Loading Linux %s ..." ${version})"
+    sed "s/^/$submenu_indentation/" << EOF
        echo    '$(echo "$message" | grub_quote)'
+EOF
+  fi
+  sed "s/^/$submenu_indentation/" << EOF
        linux   ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
 EOF
   if test -n "${initrd}" ; then
     # TRANSLATORS: ramdisk isn't identifier. Should be translated.
-    message="$(gettext_printf "Loading initial ramdisk ...")"
+    if [ x"$quiet_boot" = x0 ] || [ x"$type" != xsimple ]; then
+      message="$(gettext_printf "Loading initial ramdisk ...")"
+      sed "s/^/$submenu_indentation/" << EOF
+       echo    '$(echo "$message" | grub_quote)'
+EOF
+    fi
     initrd_path=
     for i in ${initrd}; do
       initrd_path="${initrd_path} ${rel_dirname}/${i}"
     done
     sed "s/^/$submenu_indentation/" << EOF
-       echo    '$(echo "$message" | grub_quote)'
        initrd  $(echo $initrd_path)
 EOF
   fi